package com.example.mysmall.mvp_rajava.ui.modules.home;


import com.example.mysmall.mvp_rajava.entity.LiveChina;
import com.example.mysmall.mvp_rajava.net.RetrofitService;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by xingge on 2017/8/15.
 */

public class HomePresenter implements HomeContract.Presenter {

    private HomeFragment homeFragment;
    @Inject
    public HomePresenter(HomeFragment homeFragment){
        this.homeFragment = homeFragment;
        this.homeFragment.setPresenter(this);
    }

    @Override
    public void start() {
        RetrofitService.create()//获取API对象
                .getLiveChina()//被观察者
                .subscribeOn(Schedulers.io())//被观察者执行在io线程中
                .observeOn(AndroidSchedulers.mainThread())//返回的数据在主线程中
                .subscribe(new Consumer<LiveChina>() {
                    @Override
                    public void accept(LiveChina liveChina) throws Exception {
                        homeFragment.showLiveChina(liveChina);
                    }
                });
    }
}
